Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

230
Views
What is wrong with the following code segment, and isn't default switch mandatory for "switch" loops?

I am tired of my university, my midterm exams and I am tired of thinking what the hell is wrong here.

double n;
n = 3.5; // line 2
switch( n){
case 2.5 : printf(“High”); break;
case 0.5 : printf(”Low”); break;}

In general, I thought default statement is missing because n is 3.5 and every switch statement we wrote included a default statement.

Options are:

  • I)default statement is missing (What I ticked.)

    II)there is an error in line 2

    III)semi colon is missing at the end of the switch statement

    IV)double data type cannot be used with switch statement (Correct answer.)

Can anyone explain me why IV is correct answer? Thank you.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

The label default may be omitted in the switch statement. However the case labels shall be of integer type.

So the switch statement is incorrect at least due to incorrect case labels.

Also the expression in the switch statement shall have an integer or an enumeration type.

over 4 years ago · Santiago Trujillo Report

0

switch work on integral values (int, enum).

If you want to "switch" on double values, you will need to use if/else statements.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!